package com.chanyachting.emall.domain;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.chanyachting.emall.dao.MenugroupDAO;
import com.chanyachting.emall.domain.base.BaseMenugroup;

/**
 * This is the object class that relates to the menugroup table.
 * Any customizations belong here.
 */
public class Menugroup extends BaseMenugroup {

/*[CONSTRUCTOR MARKER BEGIN]*/
	public Menugroup () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Menugroup (java.lang.Integer _id) {
		super(_id);
		
		Menugroup mg=(Menugroup)new MenugroupDAO().load(Menugroup.class, _id);
		
		if(mg!=null){
			
			try {
				BeanUtils.copyProperties(this, mg);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * Constructor for required fields
	 */
	public Menugroup (
		java.lang.Integer _id,
		java.lang.String _name) {

		super (
			_id,
			_name);
	}

/*[CONSTRUCTOR MARKER END]*/
	
	private List<Opertionmenu> menuList;  //菜单组下的菜单列表
	
	
	
	
	
	

	public static List list(){
		
		return new MenugroupDAO().find("from Menugroup");
	}
	
	
	public void setMenuList(List<Opertionmenu> menuList) {
		this.menuList = menuList;
	}
	
	
	public List<Opertionmenu> getMenuList(){
		
		if(this.menuList!=null && this.menuList.size()>0){
			
			return this.menuList;
		}
		else{
			
			List list=Opertionmenu.listByGorupId(this.getId());
			
			this.setMenuList(list);
			
			return list;
			
		}
		
	}
	
	
	public boolean save(){
		
		new MenugroupDAO().save(this);
		
		return true;
	}
	
	
	public boolean update(){
		
		new MenugroupDAO().update(this);
		
		return true;
	}
	
	
	public boolean delete(){
		
		new MenugroupDAO().delete(this);
		
		return true;
	}
}